package com.breeze.blockchain.message;

import com.breeze.blockchain.message.test.TestDelayExecutor;
import com.breeze.blockchain.message.test.TestDelayMessage;
import com.breeze.components.message.delay.executor.DelayQueueExecutor;
import com.breeze.components.message.delay.executor.DelayQueueExecutorEngine;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 延迟队列配置
 *
 * @author breeze
 */
@Configuration
@ConditionalOnClass(DelayQueueExecutor.class)
public class DelayQueueConfig {

  @Resource RedissonDelayQueueHolder redissonDelayQueueHolder;

  /** 绑定延迟队列消息和执行器 */
  @Bean
  public DelayQueueExecutorEngine<TestDelayMessage> testDelayQueueExecutorEngine(
      TestDelayExecutor delayExecutor) {
    return new DelayQueueExecutorEngine<>(
        redissonDelayQueueHolder, delayExecutor, TestDelayMessage.class);
  }
}
